package com.wcsy.myblog.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wcsy.myblog.dao.CollectMapper;
import com.wcsy.myblog.entity.Collect;
import com.wcsy.myblog.service.ICollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Service
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect> implements ICollectService {
    @Autowired
    CollectMapper collectMapper;
    /**
     * 查询该文章被几人收藏
     */
      public List<Collect> selectCount(int articleId){
          return collectMapper.selectCount(articleId);
      }

    @Override
    public Boolean SelectIsCollect(int userId,int articleId) {
        //查询用户是否已关注这篇文章
        Collect one = collectMapper.selectOne(new QueryWrapper<Collect>().
                eq("user_id", userId).eq("article_id", articleId));
        if(one!=null){
          return true;
        }
        return false;
    }
}
